Macros/cs

Úvod

Makra představují pohodlný způsob, jak ve FreeCADu opakovat složité úkony. Stačí jednoduše zaznamenat úkony tak, jak je provádíte, poté je uložit pod určitým názvem a kdykoli je chcete, je znovu spustit. Jelikož jsou makra ve skutečnosti seznamem příkazů v jazyce Python, můžete je také upravovat a vytvářet tak velmi složité skripty.

While Python scripts normally have the .py extension, FreeCAD macros should have the .FCMacro extension. A collection of macros written by experienced users is found in the macros recipes page.

See the Power users hub to learn more about the Python programming language, and about writing macros. In particular, you should start with these pages:

Jak to funguje

Enable the console output in the menu Edit → Preferences → Python → Macro → Show scripts commands in Python console. You will see that in FreeCAD, every action you do, such as pressing a button, outputs a Python command. Those commands are what can be recorded in a macro. The main tool for making macros is the macros toolbar: . On it you have 4 buttons: Record, stop recording, edit and play the current macro.

Použití je velmi jednoduché: Stisknete tlačítko Spustit záznam, nejdříve zadáte jméno makra a potom provádíte požadované operace. Když jste hotovi, kliknete ma Zastavit záznam a provedené operace budou uloženy. Nyní máte přístupný i editovací režim pod tlačítkem Upravit záznam.

Macro dialog, listing the macros available in the system

V tom můžete pracovat s makrem, můžete je smazat, upravovat, kopírovat, instalovat nebo vytvářet zcela nové. Když makro upravujete, bude otevřeno v editovacím okně, kde můžete dělat změny v jeho kódu.

Příklad

Press the record button, give a name, let's say "cylinder 10x10", then, in the Part Workbench, create a cylinder with radius = 10 and height = 10. Then, press the "stop recording" button. In the edit macros dialog, you can see the Python code that has been recorded, and, if you want, make alterations to it. To execute your macro, simply press the execute button on the toolbar while your macro is in the editor. You macro is always saved to disk, so any change you make, or any new macro you create, will always be available next time you start FreeCAD.

Přizpůsobení

Of course it is not practical to load a macro in the editor in order to use it. FreeCAD provides much better ways to use your macro, such as assigning a keyboard shortcut to it or putting an entry in the menu. Once your macro is created, all this can be done via the Tools → Customize menu.

Tímto způsobem můžete ze svého makra udělat skutečný nástroj, stejně jako jakýkoli standardní nástroj ve FreeCADu. To, spolu s možnostmi skriptování v jazyce Python v rámci FreeCADu, umožňuje snadno přidávat do uživatelského rozhraní vlastní nástroje.

Podrobnější popis najdete na stránce Přizpůsobení panelů nástrojů.

Vytváření maker bez záznamu

You can also directly copy/paste Python code into a macro, without recording GUI action. Simply create a new macro, edit it, and paste your code. You can then save your macro the same way as you save a FreeCAD document. Next time you start FreeCAD, the macro will appear under the "Installed Macros" item of the Macro menu.

See How to install macros for a more detailed description.

Repozitář maker

There are two main places for macros. The first one is the official peer-reviewed macro repository on GitHub. The second one is the Macros recipes page from which you can pick some useful macros to add to your FreeCAD installation. Macros from both repositories can be installed via the Addon Manager directly from FreeCAD.

Dodatečné informace

Návody

Rozšíření můžete nainstalovat manuálně, mnohem jednodušší je však použít Správce doplňků.